<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>忘记密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/login.css" media="all">
</head>
<body>
<div class="user-login user-display-show layui-bg-gray" id="user-login-container" style="display: none;">
    <div class="user-login-main">
        <div class="user-login-box user-login-header">
            <h2>BASE4WEB</h2>
            <p>XXXX后台管理系统</p>
        </div>
        <form class="user-login-box layui-form" id="forget-form">

        </form>
    </div>
</div>
<script id="getpass" type="text/html">
    <div class="layui-form-item">
        <label class="user-login-icon layui-icon layui-icon-cellphone" for="forget-cellphone"></label>
        <input type="text" name="cellphone" id="forget-cellphone" lay-verify="phone" placeholder="请输入注册时的手机号" class="layui-input">
    </div>
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-xs7">
                <label class="user-login-icon layui-icon layui-icon-vercode" for="forget-vercode"></label>
                <input type="text" name="vercode" id="forget-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
            </div>
            <div class="layui-col-xs5">
                <div style="margin-left: 10px;">
                    <img src="https://www.oschina.net/action/user/captcha" class="user-login-codeimg" id="LAY-user-get-vercode">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-xs7">
                <label class="user-login-icon layui-icon layui-icon-vercode" for="forget-smscode"></label>
                <input type="text" name="vercode" id="forget-smscode" lay-verify="required" placeholder="短信验证码" class="layui-input">
            </div>
            <div class="layui-col-xs5">
                <div style="margin-left: 10px;">
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="forget-getsmscode">获取验证码</button>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="forget-submit">找回密码</button>
    </div>
</script>
<script id="resetpass" type="text/html">
    <div class="layui-form-item">
        <label class="user-login-icon layui-icon layui-icon-password" for="forget-password"></label>
        <input type="password" name="password" id="forget-password" lay-verify="pass" placeholder="新密码" class="layui-input">
    </div>
    <div class="layui-form-item">
        <label class="user-login-icon layui-icon layui-icon-password" for="forget-repass"></label>
        <input type="password" name="repass" id="forget-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="forget-resetpass">重置新密码</button>
    </div>
</script>
<script src="layui/layui.js"></script>
<script>
    layui.use(['form','laytpl'], function(){
        var $ = layui.$
        ,form = layui.form
        ,laytpl = layui.laytpl;

        var data={};
        //验证信息模版
        var getTpl = getpass.innerHTML;

        //重置密码模版
        var resetTpl = resetpass.innerHTML;

        //模版切换视图
        var view = document.getElementById('forget-form');

        //渲染模版
        laytpl(getTpl).render(data,function(html){
            view.innerHTML = html;
        });


        form.render();

        //找回密码下一步
        form.on('submit(forget-submit)', function(obj){
            var field = obj.field;

            //请求接口
            $.ajax({
                type: "POST",//方法类型
                async: false, // 使用同步方式
                dataType: "json",//预期服务器返回的数据类型
                url: "" ,//url
                data: field,
                success: function (result) {
                    var data= result.data;
                    if (result.status == 1) {
                        laytpl(resetTpl).render(data,function(html){
                            view.innerHTML = html;
                        });
                    }else{
                        layer.msg(result.msg);
                    }
                },
                error : function() {
                    layer.msg('网络异常!');
                }
            });

            return false;
        });

        //重置密码
        form.on('submit(forget-resetpass)', function(obj){
            var field = obj.field;

            //确认密码
            if(field.password !== field.repass){
                return layer.msg('两次密码输入不一致');
            }

            //请求接口
            $.ajax({
                type: "POST",//方法类型
                async: false, // 使用同步方式
                dataType: "json",//预期服务器返回的数据类型
                url: "" ,//url
                data: field,
                success: function (result) {
                    var data= result.data;
                    if (result.status == 1) {
                        layer.msg('密码已成功重置', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            location.href = 'login.html'; //跳转到登录页
                        });
                    }else{
                        layer.msg(result.msg);
                    }
                },
                error : function() {
                    layer.msg('网络异常!');
                }
            });

            return false;
        });

    });
</script>
</body>
</html>